import { createBrowserRouter, Navigate } from 'react-router-dom';

// 导入页面组件
import Login from '../views/Login';
import Register from '../views/Register';
import HomeView from '../views/HomeView';
import User from '../home/User';
import Market from '../home/Market';
import Detail from '../home/Detail';
import RecStudent from '../home/RecStudent';
import Upload from '../home/Upload';

// 定义路由配置
const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to="/login" replace />
  },
  {
    path: '/login',
    element: <Login />
  },
  {
    path: '/reg',
    element: <Register />
  },
  {
    path: '/home',
    element: <HomeView />,
    children: [
      {
        path: '',
        element: <Navigate to="market" replace />
      },
      {
        path: 'user',
        element: <User />
      },
      {
        path: 'upload',
        element: <Upload />
      },
      {
        path: 'market',
        element: <Market />
      },
      {
        path: 'detail/:id',
        element: <Detail />
      },
      {
        path: 'recommend',
        element: <RecStudent />
      }
    ]
  }
]);

// 路由守卫功能可以通过React Router的loader或useEffect实现
// 这里我们将在main.jsx中使用路由守卫

export default router;